Ext.user.Rabcitem = {};
	Ext.user.Rabcitem.itemscheckbox = function(ids,array){
		this.itemscheckbox = [];
		this.name = [];
		if(ids.itemcheckbox[array.id] == null) return this.itemscheckbox;
		var j =0;
		for(var i in ids.itemcheckbox[array.id]){
			this.name[i] = {};
			this.name[i].id = i;
			this.name[i].title = ids.itemcheckbox[array.id][i].title;
			this.name[i].name = ids.itemcheckbox[array.id][i].name;
			if(ids.itemcheckbox[array.id][i].checked) 
			{
				this.itemscheckbox[j] = {checked:true,id:'rabc_' + this.name[i].id,xtype: 'checkbox',boxLabel: this.name[i].title,style: 'margin-left:5px;',value:this.name[i].id,inputValue: this.name[i].id,name: 'roleid[]'};
			}
			else
			{
				this.itemscheckbox[j] = {id:'rabc_' + this.name[i].id,xtype: 'checkbox',boxLabel: this.name[i].title,style: 'margin-left:5px;',value:this.name[i].id,inputValue: this.name[i].id,name: 'roleid[]'};
			}	
			j ++;
		}
		return this.itemscheckbox;
	}
	Ext.user.Rabcitem.group = function(groupids,arr){
		this.group = [];
		this.arr = [];
		var j =0;
		for(var i in groupids.group[arr.id]){
			this.arr[i] = {};
			this.arr[i].id = i;
			if(groupids.group[arr.id][i].checked)
				this.arr[i].title = '<input type="checkbox" checked name="roleid[]"  value="'+ this.arr[i].id +'" style="margin-left: 5px; ">' + groupids.group[arr.id][i].title;
			else
				this.arr[i].title = '<input type="checkbox"  name="roleid[]"  value="'+ this.arr[i].id +'" style="margin-left: 5px; ">' + groupids.group[arr.id][i].title;
			this.bb = new Ext.user.Rabcitem.itemscheckbox(groupids,this.arr[i]);
			this.group[j] = {id:'rabc_' + this.arr[i].id,height:200,xtype: 'fieldset',title: this.arr[i].title,columnWidth: 0.2,style: 'margin-left:3px;margin-top:5px;margin-bottom:5px;',labelAlign: 'right',
            items: [{xtype: 'panel',title: '',border: false,items:this.bb}]};
			j ++;
		}
		return this.group;
	}
	Ext.user.Rabcitem.rabc = function(rabcids){
		this.rabc =[];
		var aa = (Ext.get('Rabcform').query('*[class=x-panel-body x-panel-body-noheader x-panel-body-noborder x-form]'))[0].id;
		var panel = Ext.getCmp('Rabcform');
		for(var i in rabcids.rabc){
			this.rabc[i] = {};
			this.rabc[i].name = 'rabc_' + rabcids.rabc[i].id;
			this.rabc[i].id = rabcids.rabc[i].id;
			this.rabc[i].title = rabcids.rabc[i].title;
			if(rabcids.rabc[i].checked)
				this.rabc[i].title = '<input type="checkbox" checked name="roleid[]"  value="'+ this.rabc[i].id +'" style="margin-left: 5px; ">' + this.rabc[i].title;
			else
				this.rabc[i].title = '<input type="checkbox" name="roleid[]"  value="'+ this.rabc[i].id +'" style="margin-left: 5px; ">' + this.rabc[i].title;
			this.aa = new Ext.user.Rabcitem.group(rabcids,this.rabc[i]);
			panel.add(new Ext.Panel({id:'rabc_' + rabcids.rabc[i].id,renderTo:aa,xtype: 'panel',autoScroll: true,
			items: [{border:false,xtype: 'panel',title: this.rabc[i].title,layout: 'column',items:this.aa}]}));
		}
		return this.rabc;
	}
	
Ext.user.RabcWindow = Ext.extend(Ext.Window, {
    title: 'My Window',
    width: 700,
    height: 500,
    autoScroll: true,
	id:'rabcwindow',
	modal:true,
	buttons:[{text:'确认权限',handler:function(a,b){
		Ext.user.method.submitForm('Rabcform','/Role/setrole/',{s:function(){
			Ext.getCmp('rabcwindow').close();
		},f:function(){
		
		}},'POST');
	}},{text:'重置',handler:function(){
		Ext.getCmp('Rabcform').form.reset();
	}}],
	successFn:function(r,o){
		this.jsonData = Ext.util.JSON.decode(r.responseText);
		this.arr = new Ext.user.Rabcitem.rabc(this.jsonData);
	},
	failureFn:function(r,o){
		alert('加载失败');
	},
	listeners:{
		show:function(c){
			Ext.Ajax.request({
			    url: Ext.user.baseUrl + '/Role/roledata/',
			    success: this.successFn,
			    failure: this.failureFn,
				params:{roleid:c.roleid}
			});
		}
	},
    initComponent: function(cfg) {
		this.cfg = cfg || {};
		this.items = [new Ext.form.FormPanel({formId:'RabcformId',border:false,id:'Rabcform'})];
        Ext.user.RabcWindow.superclass.initComponent.call(this);
    }
});
Ext.user.RoleWindow = Ext.extend(Ext.Window, {
    title: '添加新组',
    width: 400,
    height: 281,
    border: false,
	id:'RoleWindow',
	modal:true,
    initComponent: function(cfg) {
		this.cfg = cfg || {};
		Ext.apply(this,this.cfg);
		
		if(typeof this.edit == 'undefined'){
			this.buttons = [{text:'添加节点',handler:function(){
				Ext.user.method.submitForm('RoleWindowform','/Role/add/',{s:function(){
					Ext.getCmp('RoleWindow').close();
					Ext.StoreMgr.lookup('RoleStore').load();
				},f:function(){
					alert('添加成功');
				}},'POST','提交中。。。');
			}},{text:'重置',handler:function(){
				Ext.getCmp('RoleWindowform').form.reset();
			}}];
		}else{
			this.buttons = [{text:'修改节点',handler:function(){
				Ext.user.method.submitForm('RoleWindowform','/Role/edit/',{s:function(){
					Ext.getCmp('RoleWindow').close();
					Ext.StoreMgr.lookup('RoleStore').load();
				},f:function(){
					alert('修改失败');
				}},'POST','提交中。。。');
					
			}},{text:'重置',handler:function(){
				Ext.getCmp('RoleWindowform').form.reset();
			}}];		
		}
        this.items = [
            {
                xtype: 'form',
                id: 'RoleWindowform',
				formId:'RoleWindowformid',
                border: false,
                items: [
                    {xtype: 'fieldset',title: '基本信息',style: 'margin:5px;',
                        items: [
                            {xtype: 'textfield',fieldLabel: '职称',anchor: '100%',name: 'ename'},
                            {xtype: 'textfield',fieldLabel: '组名称',anchor: '100%',name: 'name'},
                            {xtype: 'combo',name: 'pid',store:Ext.user.method.grouproleidstore,displayField:'name',
							valueField:'id',editable:false,typeAhead: true,forceSelection: true,mode: 'local',triggerAction: 'all',
							selectOnFocus:true,fieldLabel: '上级组',anchor: '100%',hiddenName:'pid',hiddenValue:'id',emptyText:'请选择',
							blankText:'不能为空',allowBlank:false},
                            {xtype: 'textarea',anchor: '100%',fieldLabel: '描述',name: 'remark'},
                            {xtype: 'combo',name: 'status',store:Ext.user.method.statusid(),displayField:'text',valueField:'value',
							editable:false,typeAhead: true,forceSelection: true,mode: 'local',triggerAction: 'all',selectOnFocus:true,
							fieldLabel: '状态',anchor: '50%',hiddenName:'status',hiddenValue:'value',emptyText:'请选择',blankText:'不能为空',
							allowBlank:false}
                        ]
                    }
                ]
            }
        ];
       Ext.user.RoleWindow.superclass.initComponent.call(this);
    }
});
